<?php

namespace fastphp\facade;
session_start();
final class Session
{

    public static function set(string $name,string $value)
    {
        $_SESSION[$name] = $value;
    }

    public static function get(string $name)
    {
        return $name ? $_SESSION[$name] ?? null : $_SESSION ;
    }

    public static function clear($name=null)
    {
        if (!empty($name)){
            unset($_SESSION[$name]);
            return;
        }
        // 循环遍历并清空 $_SESSION 数组中的每个元素
        foreach ($_SESSION as $key => $value) {
            unset($_SESSION[$key]);
        }
    }

}